#include<bits/stdc++.h>
#define PII pair<int,int>
typedef long long ll;
using namespace std;
const int N=1e5+5;
const int maxL=1e6+5;
int n,m,L,V;
int d[N],v[N],a[N];
array<ll,3>lr[N];
int p[N];
int book[N];
int sum[maxL];
void cal(){
    for(int i=1;i<=n;i++){
        lr[i][1]=L,lr[i][0]=d[i];
        lr[i][2]=i;
        if(a[i]==0){
            if(v[i]<=V)book[i]=1;
            continue;
        }
        if(a[i]<0)lr[i][1]=min(lr[i][1],1ll*v[i]*v[i]/(-2ll*a[i])+d[i]);
        if(a[i]<0){
            if(v[i]>V)lr[i][1]=min(lr[i][1],(1ll*v[i]*v[i]-1ll*V*V-1)/(-2ll*a[i])+d[i]);
            else book[i]=1;
        }
        if(a[i]>0){
            if(v[i]<=V){
                ll pos=(1ll*V*V-1ll*v[i]*v[i])/(2ll*a[i])+1+d[i];
                if(pos>L)book[i]=1;
                else lr[i][0]=pos;
            }
        }
    }
}
ll tr[maxL];
void add(int p,int k){
    for(;p<=L+1;p+=p&-p)tr[p]+=k;
}
ll query(int p){
    ll res=0;
    for(;p;p-=p&-p)res+=tr[p];
    return res;
}
void solve1(){
    for(int i=1;i<=L+1;i++)sum[i]=0;
    for(int i=1;i<=m;i++)sum[p[i]+1]++;
    for(int i=1;i<=L+1;i++)sum[i]+=sum[i-1];
    int ans=0;
    for(int i=1;i<=n;i++){
        if(book[i])continue;
        if(sum[lr[i][1]+1]-sum[lr[i][0]])ans++;
        else book[i]=1;
    }
    printf("%d ",ans);
}
bool cmp(array<ll,3>x,array<ll,3>y){
    return x[1]<y[1];
}
void solve2(){
    for(int i=1;i<=L+1;i++)tr[i]=0;
    sort(lr+1,lr+1+n,cmp);
    int ans=0;
    for(int i=1;i<=n;i++){
        if(book[lr[i][2]])continue;
//        cout<<lr[i][0]<<' '<<lr[i][1]<<endl;
        if(query(lr[i][1]+1)-query(lr[i][0])>0)continue;
        int j=upper_bound(p+1,p+1+m,lr[i][1])-p-1;
        add(p[j]+1,1),ans++;
    }
    printf("%d",m-ans);
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d%d",&n,&m,&L,&V);
        for(int i=1;i<=n;i++)scanf("%d%d%d",&d[i],&v[i],&a[i]),book[i]=0;
        for(int i=1;i<=m;i++)scanf("%d",&p[i]);
        cal();
//        for(int i=1;i<=n;i++)printf("%d %d\n",lr[i][0],lr[i][1]);
        solve1();
        solve2();
        puts("");
    }
	return 0;
}
